//
//  XSBaojiaCell.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2024/8/2.
//  Copyright © 2024 zwb. All rights reserved.
//

import UIKit
import Kingfisher
 
class XSBaojiaCell: ZTBComCell {
    var one = ZyaZtbContentModel(JSON:["":""])! {
        didSet {
            
            if one.zStatus == "1" {
                chengjiaoImg.isHidden = false
            } else {
                chengjiaoImg.isHidden = true
            }
            
            
            btnDtradeType.setTitle(zyacatDicDesc[one.zDtradeType.unwrap].unwrap, for: .normal)
             
                lab1.text = one.zTitle
                var real_status = one.zStatus.isSome ? intTran(one.zStatus) : intTran(one.zZbStatus)
            if one.innerType! == .jpMyjpKHW {
                real_status = intTran(one.zZbStatus)
            }
            if one.innerType! == .tbMytbKHW {
                real_status = intTran(one.zZbStatus)
            }
            let btnName =  bottomStatusBg.statusBtn.setZBJPStatus(listType:one.listType,auditmark: intTran(one.zAuditMark), status: real_status,tbType: one.innerType!)
                let ssst = btnName == "未开始" ? "\(one.zBeginDate.unwrap)开始" : "\(one.zEndDate.unwrap)结束"
 
            bottomStatusBg.lab2.normalText =  "\(ssst)"
            bottomStatusBg.lab2.endDate = one.zEndDate
            bottomStatusBg.lab2.updateTimeShow()
            bottomStatusBg.lab2.startUpdating()
            
            
            
            
            var cityshow = one.zCity.unwrap
             if one.zBidCount == "0" || one.zBidCount.unwrap == "" {
                // 不显示
            } else {
                cityshow += "   \(one.zBidCount.unwrap)次出价"
            }
           
                labCity.text = cityshow
                lab4.text = one.zPriceRank.unwrap
                chujiaLab.text = "\(intTran(one.zBidCount))次出价"
                
            
            judgeAddtime(one)
               
         
                
                let urlR = configKSURL(one)
                
                if  let imageUrl = URL(string:urlR) {
                    let resource = KF.ImageResource(downloadURL: imageUrl)
                    imageV.kf.setImage(with: resource, placeholder: UIImage(named:"defaultImg"))
                }
                
         
            
        }
    }
}

 

func configKSURL(_ one:ZyaZtbContentModel) -> String {
    var url = ""
    
    KSLog("路径-----------")
    KSLog(one.idKey.unwrap)
    KSLog(one.zTitle.unwrap)
     KSLog(one.zMainUrl.unwrap)
    
   
    if one.zMainUrl.unwrap.contains("sid") {
        url = one.zMainUrl.unwrap
    } else {
        url = "\(one.zMainUrl.unwrap)?sid=\(one.sid.unwrap)"
    }
    if !url.contains("http") {
        url = USERINFO.picUrl.unwrap + url
    }
    url = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed).unwrap

    KSLog(url)
    return url
}
